package com.huhu.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class PowerAop {
	
	Logger logger=LoggerFactory.getLogger(PowerAop.class);
	
   /**
    * 切点
    * 使用public修饰符匹配，任意返回值，在com.huhu.controller包下以Controller结尾的类名
    * 下的任意方法
    */
	@Pointcut("execution(public * com.huhu.controller..*Controller.*(..))")
	public void power() {
	}
	
	@Before("power()")
	public void before(JoinPoint joinPoint) {
		//参数
		logger.info("args={}",joinPoint.getArgs());
	}
	
	@Around("power()")
	public Object around(ProceedingJoinPoint point) throws Throwable {
		//point.getSignature().getName();
		String token="huhu1203";
		//System.out.println((point.getArgs())[0]);
		if((point.getArgs()[0].equals(token))) {
			return point.proceed();
		}
		return com.huhu.response.Response.searchByerror("您没有权限！");
	}
	

}
